package com.usian.behavior.service.impl;

import com.usian.behavior.mapper.FollowBehaviorEntryMapper;
import com.usian.behavior.service.ApFollowBehaviorService;
import com.usian.behavior.service.BehaviorEntryService;
import com.usian.model.base.BaseServiceImpl;
import com.usian.model.behavior.dtos.FollowBehaviorDto;
import com.usian.model.behavior.pojos.ApBehaviorEntry;
import com.usian.model.behavior.pojos.ApFollowBehavior;
import com.usian.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class ApFollowBehaviorServiceImpl extends BaseServiceImpl<FollowBehaviorEntryMapper, ApFollowBehavior> implements ApFollowBehaviorService {
    @Autowired
    private BehaviorEntryService behaviorEntryService;

    @Override
    public ResponseResult saveFollowBehavior(FollowBehaviorDto dto) {
        if (dto == null) return paramError;
        //行为实体表
        ApBehaviorEntry entry = behaviorEntryService.findByUserIdOrEquipmentId(dto.getUserId());
        ApFollowBehavior behavior = new ApFollowBehavior();
        behavior.setArticleId(dto.getArticleId());
        behavior.setCreatedTime(new Date());
        behavior.setEntryId(entry.getId());
        behavior.setFollowId(dto.getFollowId());
        save(behavior);
        return okResult;
    }
}
